/**
 * Created by trisatria on 3/6/14.
 */
$(document).on('pageshow','#profile', function(){
    var info_user = $.session.get("logged");
    //logged
    if(typeof  info_user != "undefined"){
        var j_user = $.parseJSON(info_user);
        console.log(j_user);
        $('#profile #view_avatar').attr('src',j_user['avatar']);
        $('#profile #name').val(j_user['name']);
        $('#profile #email').val(j_user['email']);
        $('#profile #add').val(j_user['address']);
        $('#profile #phone').val(j_user['phone']);
        $('#id').val(j_user['id']);
        $('#avatar').val(j_user['avatar']);
        $('#img_avatar').attr('src',_host_img+'/'+j_user['avatar']);
    }
    //not logged
    if(typeof  info_user == "undefined"){

    }
});
$(document).on('click','#btn_avatar',function(){
    $('#profile #popupavaatar').popup('open');
});
/*
$(document).on('click','#btn-edit', function(){
    $.mobile.loading('show');
    var avatar =  $('.thumb_border img').attr('src');
    var name =    $('#profile #name').val();
    var pass =  $('#profile #password').val();
    var re_pass =  $('#profile #re_password').val();
    var add = $('#profile #add').val();
    var phone = $('#profile #phone').val();
    var id = $('#profile #hide_id').val();
    if(pass != re_pass){
        return false;
    }
    $.ajax({
        url: _host + 'user/editprofile',
        type: 'POST',
        data: { id: id, name: name, password: pass, address: add, phone: phone, avatar: avatar }
    }).done(function(data){
        console.log(data);
        $.removeCookie("logged");
        $.cookie("logged",data);
        $.mobile.loading('hide');
    });
});*/